//
//  ZJBreakAccountVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/28.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJBreakAccountVC.h"
#import "ZJBreakAccountModel.h"
#import "ZJBreakCell.h"

@interface ZJBreakAccountVC ()
/**<模型数组>*/
@property (nonatomic,strong) NSMutableArray *modelArr;
@property (strong, nonatomic) ZJUserModel * userModel;
@end

@implementation ZJBreakAccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.userModel = GET_USERINFO;
    self.view.backgroundColor = RGB(242, 242, 242);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZJBreakCell class]) bundle:nil] forCellReuseIdentifier:@"ZJBreakCell"];
    [self sendRequest];
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   [tableView tableViewDisplayWitMsg:kNoDataImgName ifNecessaryForRowCount:self.modelArr.count];
    return self.modelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZJBreakCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJBreakCell"];
    ZJBreakAccountModel * model = self.modelArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.mainTitle.text = [NSString stringWithFormat:@"优惠%@",[NSString stringWithFormat:@"%C",(unichar)('A'+indexPath.row)]];
    cell.userModel = self.userModel;
    cell.model = model;
    cell.backgroundColor = [UIColor clearColor];

    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    ZJBreakAccountModel *model = self.modelArr[indexPath.row];
    CGFloat height = [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[ZJBreakCell class] contentViewWidth:[Utils cellContentViewWith]];

    return height;;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - ******************请求数据
-(void)sendRequest{
    [HUD showLoading:@"加载数据中..."];
    NSDictionary *parameter = [LRNetwork requestParameter:@{}];
    NSString *url = [LRNetwork requestURL:@"cgi/discount.php"];
    
    [LRNetwork netRequestPOSTWithRequestURL:url withParameter:parameter withReturnValeuBlock:^(id returnValue) {
        
        self.modelArr = [ZJBreakAccountModel mj_objectArrayWithKeyValuesArray:returnValue[@"discount"]];
        [self.tableView reloadData];
        [HUD hide];
    } withErrorCodeBlock:^(NSInteger errorCode, NSString *errorMessage) {
        [HUD showErrorMsg:errorMessage];
    } withFailureBlock:^{
        
    }];
}

@end
